package com.dk.controller;

import com.dk.pojo.TabSeller;
import com.dk.service.SellerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("seller")
@Controller
public class SellerController {
    @Autowired
    SellerService sellerService;

    @RequestMapping("getInfo")
    @ResponseBody
    public List<TabSeller> getInfo() {
        return sellerService.getInfo();
    }

    @RequestMapping("toAdd")
    public String toAdd() {
        return "Seller/add";
    }

    @RequestMapping("insertInfo")
    @ResponseBody
    public boolean insertInfo(TabSeller seller) {
        int i = sellerService.insertInfo(seller);
        return i > 0;
    }

    @RequestMapping("toUpdate/{id}")
    public String toUpdate(@PathVariable("id") Integer id, Model model) {
        TabSeller seller = sellerService.getInfoById(id);
        model.addAttribute("seller", seller);
        return "Seller/update";
    }
    @RequestMapping("updateSeller")
    @ResponseBody
    public boolean updateSeller(TabSeller seller){
        int i = sellerService.updateSeller(seller);
        return i>0;
    }

    @RequestMapping("deleteSellerById/{id}")
    @ResponseBody
    public boolean deleteSellerById(@PathVariable("id")Integer id){
        int i = sellerService.deleteSellerById(id);
        return i>0;
    }

}